import store from '@/store/index.js'
import websocket from "@/common/websocket.js"
import {sub} from "@/common/event.js"
export default {
	namespaced: true,
	state: {
		connectState: false
	},
	mutations: {
		setConnectSuccess:(state,payload)=>{
			state.connectState = true
		},
		setConnectState: (state, payload) => {
			if(payload){
				// 注册流程
				const user = uni.getStorageSync("user")
				if(user && user.id){
					websocket.send({
						type:"register",
						data:{}
					})
				}else{
					sub("userInit",function(){
						websocket.send({
							type:"register",
							data:{}
						})
					})
				}
			}else{
				state.connectState = payload
			}
			
		}
	},
	actions: {
		setName({
			commit
		}, {
			payload
		}) {
			console.log("vuex action", payload)
			// commit('setNameState', payload)
		},
	},
	init: function() {
		console.log(`执行初始化`)
		
	}
}